package com.sinai.mshab.server.sql;

/**
 * Implements the {@link Limit} interface to allow setting a limit on a sql
 * statement. At the moment this will only work with MySQL.
 * 
 * @author Arthur Kalmenson
 */
public class LimitImpl implements Limit {

	/**
	 * The offset for this limit.
	 */
	private int offset;
	
	/**
	 * The number of rows to effect.
	 */
	private int rows;
	
	/**
	 * Sets a limit on which elements the query is to effect.
	 * 
	 * @param offset
	 *            on which element to start applying the query.
	 * @param rows
	 *            how many rows after the offset to apply the query to.
	 */
	public LimitImpl(int offset, int rows) {
		this.offset = offset;
		this.rows = rows;
	}
	
	public String getFormattedSQL() {
		
		// create the MySQL formatted LIMIT.
		String limit = " LIMIT " + offset + ", " + rows + " ";
		
		return limit;
	}

}
